<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Index_Category extends Controller_Index_Base
{
	public function action_index()
	{    
        $category_id = $this->request->param('id');
        $page        = $this->request->param('page') ? $this->request->param('page') : 1;       
        $category    = ORM::factory('category', $category_id);

        $suppliers   = ORM::factory('supplier')->get_suppliers($category, $page);
        Model_Stat::update_suppliers_views($suppliers);
        
        $content = new View('index/category/index_tpl');
        $content->suppliers = $suppliers;
        $content->category  = $category;

        $content->count   = ORM::factory('supplier')->get_suppliers($category, null, true);
        $content->pagination = array(
            'page'     => $page,
            'per_page' => ORM::factory('supplier')->get_suppliers_per_page(),
        );
        
        $this->print_template($category->name, $content, $category);
	}
} 
